package generator.mybatis;

import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.core.io.ClassPathResource;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

@SpringBootApplication
public class MybatisApplication {

    public static void main(String[] args) throws Exception {
        generator();
        //SpringApplication.run(MybatisApplication.class, args);
    }

    private static void generator() throws Exception {
        List<String> warnings = new ArrayList<>();
        //指定逆向工程配置文件
        ClassPathResource classPathResource = new ClassPathResource("generatorConfig.xml");
        File configFile = classPathResource.getFile();
        ConfigurationParser cp = new ConfigurationParser(warnings);
        Configuration config = cp.parseConfiguration(configFile);
        DefaultShellCallback callback = new DefaultShellCallback(true);
        MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
        myBatisGenerator.generate(null);

        // todo if (rs.getString("TABLE_CAT").contains("crm16")) {
    }

}
